/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import com.opensymphony.xwork2.ActionContext;
import dao.ProfileDAO;
import dao.UserDAO;
import dto_pakinfo.Profile;
import java.util.Map;
import javax.security.auth.login.FailedLoginException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import util.StringUtil;

/**
 *
 * @author Thinh
 */
public class UserController extends BaseController {

    private ProfileDAO profileDAO;
    private Profile profile;
    private int userId;
    private Log log = LogFactory.getLog(Profile.class);
    //   private User

    public UserController() {
        super();
        profileDAO = new ProfileDAO(Profile.class);
    }

    public String viewProfile() {
        try {
            profileDAO.openSession();
            Map session = ActionContext.getContext().getSession();
            Object tempUserId = session.get(StringUtil.USERID);
            if (tempUserId != null) {
                userId = (Integer) tempUserId;
                profile = profileDAO.get(userId);
            }
        } catch (HibernateException e) {
            log.error("UserController.viewProfile() ", e);
            return ERROR;
        } catch (Exception e) {
            log.error("UserController.viewProfile() ", e);
            return ERROR;
        } finally {
            profileDAO.closeSession();
        }
        return SUCCESS;
    }



    /**
     * @return the profile
     */
    public Profile getProfile() {
        return profile;
    }

    /**
     * @param profile the profile to set
     */
    public void setProfile(Profile profile) {
        this.profile = profile;
    }

    /**
     * @return the userId
     */
    public int getUserId() {
        return userId;
    }

    /**
     * @param userId the userId to set
     */
    public void setUserId(int userId) {
        this.userId = userId;
    }
}
